package com.wlyuan.open.scanner.utils.enums.order;

import com.wlyuan.core.marker.NamedValue;
import com.wlyuan.core.marker.NamedValueMap;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.Map;

/**
 * @author lijing
 * @description 订单状态新老系统对应关系
 */
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
@Getter
public enum OrderStatusEnum implements NamedValue<Integer> {

    /**
     * 新单据
     */
    NEW_ORDER(0, null, "新单据"),
    /**
     * 草稿
     */
    DRAFT(-1, null, "草稿"),

    /**
     * 待调度
     */
    WAIT_DISPATCH(1, 10, "待调度"),

    /**
     * 待签收
     */
    WAIT_SIGN(2, 20, "待签收"),

    /**
     * 待回单
     */
    WAIT_RECEIPT(4, 30, "待回单"),

    /**
     * 已回单
     */
    DONE(8, 40, "已回单"),

    /**
     * 已关闭
     */
    CLOSE(32, 50, "已关闭"),

    /**
     * 兼容老数据（16已无用）
     */
    ALREADY(16, 50, "已结账");


    private final Integer value;
    private final Integer newValue;
    private final String name;


    private static final Map<Integer, OrderStatusEnum> MAP = new NamedValueMap<>(OrderStatusEnum.class);

    public static OrderStatusEnum fromValue(Integer value) {
        return MAP.get(value);
    }

    public static boolean isClose(Integer val) {
        return CLOSE.getValue().equals(val);
    }

    public static boolean isWaitReceipt(Integer val) {
        return WAIT_RECEIPT.getValue().equals(val);
    }

    public static boolean isWaitDispatch(Integer val) {
        return WAIT_DISPATCH.getValue().equals(val);
    }

    public static boolean isSync(Integer val) {
        return DRAFT.getValue().equals(val) || NEW_ORDER.getValue().equals(val);
    }

    public static boolean isSignerZero(Integer val) {
        return WAIT_DISPATCH.getValue().equals(val) || WAIT_SIGN.getValue().equals(val) || CLOSE.getValue().equals(val);
    }
}
